using SuperScrollView;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// ��ͼ  ��֤����������
/// </summary>
public class SuperListView : UiView
{

    private static string prefabName = "SuperListItem";
    private SuperListModule superListModule;
    private SuperListModuleData superListModuleData;

    /// <summary>
    /// ���Խ�������Item���µ��ڴ���������ڴ�ռ�ù���
    /// ͬʱ����N��Item��ֻ������Ұ�ڵ�Item��
    /// ���׻���SuperGridItem
    /// </summary>
    public LoopListView2 loopListView2;

    public override void Awake()
    {
        //获取Ui配置
       // SetUIConfig(UiConfigManger.GetConfig((int)ViewId.SuperList));
        //superListModule = GameModuleManager.Instance.GetModule<SuperListModule>();
        //superListModule.superListView = this;
    }

    private void Start()
    {
        //注册到GameUi
        //GameUi.Instance.AddView(this);
    }




    public void UpdateState()
    {

    }
        

    private LoopListViewItem2 OnGetItemByIndex(LoopListView2 loopListView2,int rowIndex)
    {
        if (rowIndex>=0)
        {
                SuperListItemData superListItemData = superListModuleData.superListItemDataList[rowIndex];
                SuperListItemView superListItemView = loopListView2.NewListViewItem(prefabName) as SuperListItemView;
                if (superListItemView!=null)
                {
                    superListItemView.SetData(superListItemData);
                    superListItemView.Initialize();
                    superListItemView.UpdateView();

                    return superListItemView;
                }
        }
        return null;
    }


    public void OnClickCloseButton()
    {
        superListModule.OnClose();
    }

    public override void SetModule(GameModule gameModule)
    {
        this.superListModule = gameModule as SuperListModule;
    }

    public override void SetModuleData(object modelData)
    {
        this.superListModuleData = modelData as SuperListModuleData;
    }

    public override void Initialize()
    {
        //��ʼ��20��ItemUi
        loopListView2.InitListView(20, OnGetItemByIndex);
    }

    public override void UpdateView()
    {
        //���ݲ�ͬ����������������
       
        if (loopListView2.ItemTotalCount != superListModuleData.superListItemDataList.Count)
        {
            loopListView2.SetListItemCount(superListModuleData.superListItemDataList.Count);
        }
        else
        {
            //ˢ������item
            loopListView2.RefreshAllShownItem();
        }
    }


}
